<template>
	<view class="content">
		<Header></Header>
		<Swiper></Swiper>
		
		{{time}}
		
	<!-- 	<image class="logo" src="/static/logo.png"></image>
		<view class="text-area">
			<text class="title">{{title}}</text>
			<button @click="login">登录</button>
			<button @click="updateTitle">修改</button>
		</view>
		<view class="" style="height: 2000px;">
			
		</view>
		底部 -->
		
		<view v-for="item in list" :key="item.id" class="">
			{{item.username}} 
			
		 	{{ timeFormat(item.addtime)}}
			
			---------------
			
			{{item.addtime | format}}
			
		</view>
	</view>
</template>

<script>
	//选项式{}api
	import Header from '../../components/index/header.vue';
	import {getNewsList} from '../../service/news.js';
	import Swiper from '../../components/index/swiper.vue';
	 import moment from 'moment';
	 import dayjs from 'dayjs'
	export default {
		components:{
			Header,Swiper
		},
		data() {
			return {
				title: 'Hello,我的uniapp项目',
				time:"",
				list:[{
                id: 1,
                username: "张三",
                addtime: "2021-10-22 17:01:40.0",
            
            },
{
                id: 2,
                username: "李四",
                addtime: "2025-10-22 17:01:40.0",
            
            }
]
			}
		},
		//过滤器
		filters:{
			format(time){
			
			  return dayjs(time).format("YYYY/MM/DD")

			}
		},
		beforeCreate() {
			//组件创建前，变量、方法未初始化完成
			// console.log(this.title);
			console.log("组件生命周beforeCreate");
		},
		created() {
			
			 // this.time=moment().format("YYYY年MM月DD日");
			
		 this.time=moment("2021-10-22 17:01:40.0").format("YYYY-MM-DD");
			
				//变量、方法初始化完成
			 console.log(this.title);
			console.log("组件生命周期函数created");
		},
		beforeMount() {
			console.log("挂载前");
			console.log("组件生命周期函数-beforeMount");
		},
		mounted() {
			console.log("挂载完成");
			console.log("组件生命周期函数mounted");
		},
		beforeUpdate() {
			
			console.log("更新前");
			console.log("组件生命周期函数beforeUpdate");
			
		},
		updated() {
			console.log("更新后");
			console.log("组件生命周期函数updated");
		},
		beforeDestroy() {
			console.log("销毁前");
			console.log("组件生命周期函数beforeDestroy");
		},
		destroyed(){
			console.log("销毁后");
			console.log("组件生命周期函数destroyed");
		},
		
		onLoad() {
			
			this.getNewsData();
			//这里可以接收参数，调接口
			console.log("页面生命周期函数onLoad");
			console.log("监听页面加载");

		},
		onShow() {
			console.log("页面生命周期函数onSHow");
		},
		onHide() {
			
			console.log("页面生命周期函数,onHide");
		},
		onReady() {
			console.log("页面生命周期函数onReady,dom挂载完成");
		},
		onUnload() {
			console.log("页面生命周期函数onUnload");
			console.log("页面销毁");
		},
		onResize(){
			console.log("页面生命周期函数onResize");
		},
		onPullDownRefresh(){
			
			console.log("页面下拉");
			console.log("下拉刷新");
			
			setTimeout(()=>{
				uni.stopPullDownRefresh();
			},2000)
			
		},
		onReachBottom(){
			console.log("页面触底");
		},
		methods: {
			
			timeFormat(time){
				
			return	moment(time).format("YYYY年MM月DD日 HH:mm")
				
			},
			
		   async getNewsData(){
			   
			 const res=  await getNewsList();
			 
			 console.log(res);
				
			},
			updateTitle(){
				
				this.title="您好世界"
				
			},
			login(){
				 
				 //保留当前页面，跳到非tabbar页面
				 uni.navigateTo({
					 url:'/pages/user/login?id=10000&type=news'
				 })
				 
				 //关闭当前页面，跳到非tabbar页面
				 // uni.redirectTo({
				 // 	url:"/pages/user/login"
				 // })
				 
			}

		}
	}
</script>

<style>
	.content {
	 
	}

	 
</style>
